package trieMatch.keywordMatcher;

/***********************************************************************************************************************
 * Container for the value and index of a token. Atoms are generated through the AtomFactory interface.
 * 
 * @author mlrus
 * 
 */
public class Atom implements Comparable<Atom> {
	// The field "index" is used in TrieMatcher.inSequence and TrieMatcher.sameSequence
	private final String value;
	private final int index;

	Atom(final String string, final int index) {
		this.value = string;
		this.index = index;
	}

	public String getValue() {
		return value;
	}

	public int getIndex() {
		return index;
	}

	@Override
	public boolean equals(final Object o) {
		return o.getClass().equals(this.getClass()) && value.equals(((Atom) o).value);
	}

	@Override
	public int hashCode() {
		return value.hashCode() + index;
	}

	public int compareTo(final Atom o) {
		return this.value == o.value ? 0 : value.compareToIgnoreCase(o.value);
	}
}